<template>
  <a-modal v-model="visible" title="考勤数据导入" @ok="onSumbit" @cancel="$emit('update:visible', false)">
    <a-form :form="form" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }" style="margin-top: 6px; margin-bottom: 12px">
      <a-form-item label="考勤记录">
        <a-select
          v-decorator="[
            'recordId',
            {
              rules: [
                {
                  required: true,
                  message: '请选择考勤记录'
                }
              ]
            }
          ]"
          placeholder="请选择"
        >
          <a-select-option :value="item.id" v-for="item in arr" :key="item.id">
            {{ item.fileName }}
          </a-select-option>
        </a-select>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import { getPageList, getImportMonthSalaryNewReq } from "@/api/wages/monthly";
import moment from "moment";
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    attendanceDataTempId: {
      type: String,
      default: ""
    },
    salaryTemplateSalaryIds: {
      type: String,
      default: ""
    }
  },
  watch: {
    visible(v) {
      if (v) this.onGetPageList();
      console.log(this.salaryTemplateSalaryIds);
    }
  },
  data() {
    return {
      form: this.$form.createForm(this, {}),
      arr: []
    };
  },
  methods: {
    moment,
    async onGetPageList() {
      try {
        const { data } = await getPageList({
          companyId: this.$store.state.hr.companyId,
          isImport: 1,
          pageNo: 1,
          pageSize: 1000
        });
        this.arr = data.entities;
      } catch (err) {
        console.log("debug log --> ", err);
      }
    },
    onSumbit() {
      this.form.validateFields((err, values) => {
        if (!err) {
          this.onGetImportMonthSallary(values.recordId);
        }
      });
    },
    async onGetImportMonthSallary(v) {
      try {
        await getImportMonthSalaryNewReq({ recordId: v, salaryTemplateSalaryIds: this.salaryTemplateSalaryIds });

        this.$notification.success({ message: "操作成功" });
        this.$emit("update:visible", false);
        this.$emit("upDate", false);
      } catch (err) {
        console.log("debug log --> ", err);
      }
    }
  }
};
</script>

<style lang="scss" scoped></style>
